/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package be.darling.scrt.data;

import be.darling.scrt.design.RandomizationTest;
import com.djahva.pax.Collector;
import com.djahva.pax.HashMapReader;
import com.djahva.pax.PaxReader;
import java.util.HashMap;

/**
 *
 * @author jingle
 */
public class XMLReader extends Reader{

    private String position;
    
    public XMLReader()
    {
        super();
    }

    public void init()
    {
        Object pos = getOption("position");
        if(pos != null)
            this.position = (String) pos;
    }

    public void read() {
        final RandomizationTest test = getRandomizationTest();

        PaxReader pax = new PaxReader();
        pax.addReader(new HashMapReader(), position + "data/point", "dataFileReader");
        pax.getReader("dataFileReader").setDestination( new Collector() {

            public void put(String key, Object value) {

                System.out.println(value);
                HashMap hMap = (HashMap)value;
                test.addObservation( (String)hMap.get("condition"), new Value(Double.parseDouble( (String)hMap.get("value") ) ) );
            }
        } );

        pax.parse((String) options.get("source"));
    }


}
